package chapter1.fileInput.task;

import java.io.*;


/*
4:获得文件行数的方法
 有 bufferedReader.readLine 方法 或者查找byte是否=='\n',比较谁快！
 */
public class Task5 {
    public static void main(String[] args) throws Exception {
        Reader fR = new FileReader("F:\\123\\12.txt");
        BufferedReader bR = new BufferedReader(fR);
        int count1 = 0;
        int count2 = 0;

        long begin1 = System.currentTimeMillis();
        while (bR.readLine() != null)
            count1++;
        long end1 = System.currentTimeMillis();
        System.out.println(end1 - begin1 + "毫秒");
        bR.close();

        FileInputStream fI = new FileInputStream("F:\\123\\12.txt");
        byte[] b = new byte[fI.available()];
        fI.read(b);
        fI.close();
        long begin2 = System.currentTimeMillis();
        for (byte b1 : b) {     
            if (b1 == 10)
                count2++;
        }
        long end2 = System.currentTimeMillis();
        System.out.println(end2 - begin2 + "毫秒");


    }
}

